home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / utils / crontab.el.z / crontab.el
Encoding:
Text File  |  1998-05-21  |  5.2 KB  |  158 lines

  1. ;; #(@) crontab.el - An Emacs function to assist in editing crontab entries
  2. ;; Last edited: Fri Aug 18 12:19:22 1989 by chris (Christopher D. Orr) on lxn
  3. ;;
  4. ;; Version: 1.00 - Initial Creation of mode
  5. ;;          1.01 - Added crontab-use-local-file variable
  6. ;;          1.02 - Reworked most of the library to be cleaner.
  7. ;;          1.03 - Now deletes blank lines in crontab entry
  8.  
  9. ;; Copyright (C) 1989 Christopher D. Orr (chris@lxn.eds.com)
  10.  
  11. ;; This file is part of XEmacs.
  12.  
  13. ;; XEmacs is free software; you can redistribute it and/or modify it
  14. ;; under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; XEmacs is distributed in the hope that it will be useful, but
  19. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21. ;; General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  25. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  26. ;; Boston, MA 02111-1307, USA.
  27.  
  28. ;;; Synched up with: Not in FSF.
  29.  
  30. ;;
  31. ;; TODO:
  32. ;;
  33.  
  34. ;; Place the following line in your ~/.emacs file:
  35. ;;    (autoload 'crontab-edit "crontab"
  36. ;;              "Function to allow the easy editing of crontab files." t)
  37. ;;
  38.  
  39. (provide 'crontab-edit)
  40.  
  41. ;;; Local Variables.  Define these to your liking.
  42.  
  43. (defgroup crontab nil
  44.   "Assist in editing crontab files."
  45.   :group 'languages)
  46.  
  47.  
  48. (defcustom crontab-filename "~/.crontab"
  49.   "*The name of the file to store the User's Crontab."
  50.   :type 'file
  51.   :group 'crontab)
  52.  
  53. (defcustom crontab-directory "/usr/spool/cron/crontabs"
  54.   "*The name of the directory in which crontab stores it's entries."
  55.   :type 'file
  56.   :group 'crontab)
  57.  
  58. (defcustom crontab-use-local-file nil
  59.   "*Non-nil means use file stored in User's Home directory, if it exists.
  60. Otherwise, always ask crontab for the current entry (maybe)."
  61.   :type 'boolean
  62.   :group 'crontab)
  63.  
  64.  
  65. ;;; Interactive Function called to edit a Crontab Entry.  It is called
  66. ;;; instead of crontab-edit to allow for future automatic entries.
  67.  
  68. (defun crontab-edit ()
  69.   "Function to allow the easy editing of crontab files."
  70.  
  71.   (interactive)
  72.   (crontab-get))
  73.  
  74.  
  75. ;;; Function to retrieve the crontab entry.  The Function will
  76. ;;; retrieve the file (crontab-filename) first.  If the file does not
  77. ;;; exists, a crontab -l command will be executed. 
  78.  
  79. (defun crontab-get ()
  80.    "Retrieve a crontab file either using crontab -l or from the variable
  81. crontab-filename"
  82.    (message "Retrieving Crontab ... ")
  83.    (switch-to-buffer (create-file-buffer crontab-filename))
  84.    (erase-buffer)
  85.  
  86.    (if (file-exists-p crontab-filename)
  87.        (if (file-newer-than-file-p (concat crontab-directory "/" (user-login-name)) (expand-file-name crontab-filename))
  88.        (if (yes-or-no-p "Cron has a more recent copy of your crontab.  Use it ? ")
  89.            (call-process "crontab" nil t t "-l")
  90.          (insert-file crontab-filename))
  91.      (if crontab-use-local-file
  92.          (insert-file crontab-filename)
  93.        (call-process "crontab" nil t t "-l")))
  94.      (if crontab-use-local-file
  95.      (insert-file crontab-filename)
  96.        (call-process "crontab" nil t t "-l")))
  97.  
  98. ;; What if crontab returns a fatal ??????  Can't we check the errorlevel ????
  99.    (goto-char (point-min))
  100.    (if (search-forward-regexp "crontab:\\|no crontab for" nil t nil)
  101.        (erase-buffer))
  102.    (if (eobp)
  103.        (crontab-initialize))
  104.    (goto-line 6)
  105.    (setq buffer-file-name crontab-filename)
  106.    (set-buffer-modified-p nil)
  107.    (make-variable-buffer-local 'write-file-hooks)
  108.    (or (memq 'crontab-save write-file-hooks)
  109.        (setq write-file-hooks 
  110.          (reverse (cons 'crontab-save (reverse write-file-hooks)))))
  111.    (message "Save file normally when finished to update cron."))
  112.  
  113.  
  114. ;;; This function is called whenever a save-file operation is
  115. ;;; performed in the crontab buffer.  It saves the crontab to the file
  116. ;;; name (crontab-filename) and then removes the crontab buffer.
  117.  
  118. (defun crontab-save ()
  119.   "Submit the edited crontab to the cron deamon for processing"
  120.  
  121.   (goto-char (point-min))
  122.   (while (not (eobp))
  123.     (delete-blank-lines)
  124.     (forward-line 1))
  125.   (redraw-display)
  126.  
  127.   (setq write-file-hooks nil)
  128.   (let ((crontab-buffer (buffer-name)))
  129.     (basic-save-buffer)
  130.  
  131. ;; What if the call-process to crontab fails ???  Can we check for a fatal ???
  132. ;;  (call-process "crontab" nil nil nil (expand-file-name crontab-filename))
  133.     (shell-command (concat "crontab " (expand-file-name crontab-filename)))
  134.  
  135.     (switch-to-buffer (other-buffer))
  136.     (kill-buffer crontab-buffer))
  137.   (message (concat "Crontab saved as " crontab-filename " and submitted to cron."))
  138. ;; fixed by Lynn D. Newton - 03/17/95
  139.   "")
  140. ;; OLD
  141. ;; nil)
  142.  
  143. (defun crontab-initialize ()
  144.   "Create a default Crontab file if one does not exist or is empty.
  145. If the function (time-stamp) is available, the last modification time will
  146. be stamped to the file."
  147.  
  148.    (insert "# Cron Table Entry for ")
  149.    (insert (user-login-name))
  150.    (insert " (")
  151.    (insert (user-full-name))
  152.    (insert ")\n# Last Edited: \n")
  153.    (insert "#\n")
  154.    (insert "# min    hr     day   mon    wday(0=sun)  cmd\n")
  155.    (insert "#\n"))
  156.  
  157. ;;; Watch out for the signature  :-)
  158.